import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import LoginView from '../views/LoginView.vue'
import HomeView from '../views/HomeView.vue'
import SearchView from '@/views/SearchView.vue'
import DetailView from '@/views/DetailView.vue'
import NotFound from '@/views/NotFound.vue'

const router = createRouter({
  // history: createWebHashHistory(),
  history: createWebHashHistory(),
  routes: [
    {
      path: '/',
      redirect: '/home' // 如果访问的是 localhost:5173/#/ => localhost:5173/#/home
    },
    {
      path: '/login',
      // component: LoginView
      component:() =>import("@/views/LoginView.vue") //路由懒加载
    }, {
      path: "/home/:id?", //?表示id可有可无
      // component: HomeView
      component:() =>import("@/views/HomeView.vue")
    },
    {
      path: '/search',
      // component: SearchView
      component:() =>import("@/views/SearchView.vue")

    },
    {
      path: '/detail/:name/:index',
      // component: DetailView
      component:() =>import("@/views/DetailView.vue")

    },
    {
      path: '/:pathMatch(.*)*',
      // component: NotFound
       component:() =>import("@/views/NotFound.vue")
    },
  ] // 对应鸿蒙的router_map.json
}) // 创建路由实例对象

export default router // 到处路由实例对象